package md.lanjing.com.module_deal_center.ui.adapter;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lxh.baselibray.util.TimeUtils;

import java.util.List;

import md.lanjing.com.module_deal_center.R;
import md.lanjing.com.module_deal_center.bean.ConsignOrderStateResponce;
import md.lanjing.com.module_deal_center.ui.activity.CheckOrderDetailActivity;


public class ConsignOrderStateAdapter extends BaseQuickAdapter<ConsignOrderStateResponce.DataBean,BaseViewHolder> {
    int type;
    public ConsignOrderStateAdapter(int layoutResId, @Nullable List<ConsignOrderStateResponce.DataBean> data) {
        super(layoutResId, data);
    }

    public void setType(int type) {
        this.type = type;
    }

    @Override
    protected void convert(BaseViewHolder helper, ConsignOrderStateResponce.DataBean item) {
        TextView tvCountDown = helper.getView(R.id.tv_count_down);
        ImageView ivStateFlag=helper.getView(R.id.iv_state_flag);
        TextView tvQueryDetail = helper.getView(R.id.tv_query_detail);
        String time=null;
        switch (type){
            case 1:
               time= TimeUtils.millis2String(Long.parseLong(item.getLockTime()));
                tvCountDown.setVisibility(View.GONE);
                ivStateFlag.setVisibility(View.VISIBLE);
                ivStateFlag.setImageResource(R.drawable.icon_lock_flag);
                tvQueryDetail.setVisibility(View.GONE);
                break;
            case 2:
                time= TimeUtils.millis2String(Long.parseLong(item.getBuyTime()));
                tvCountDown.setVisibility(View.VISIBLE);
                tvCountDown.setText("剩余："+item.getRemainingTime());

                tvQueryDetail.setVisibility(View.VISIBLE);
                tvQueryDetail.setOnClickListener(v -> {
                    Intent intent = new Intent(mContext, CheckOrderDetailActivity.class);
                    intent.putExtra(CheckOrderDetailActivity.TRANSFER_ID,item.getTransferId());
                    mContext.startActivity(intent);
                });
                break;
            case 3:
                time= TimeUtils.millis2String(Long.parseLong(item.getConfirmTime()));
                tvCountDown.setVisibility(View.GONE);
                ivStateFlag.setVisibility(View.VISIBLE);
                ivStateFlag.setImageResource(R.drawable.icon_finish_flag);
                tvQueryDetail.setVisibility(View.GONE);
                break;
        }
        helper.setText(R.id.tv_buy_id,"购买人ID："+item.getBuyerId())
                .setText(R.id.tv_order_number,"订单号："+item.getBillId())
                .setText(R.id.tv_order_time,time)
                .setText(R.id.tv_buy_number,"购买"+item.getType()+"数量："+item.getBuyTokenNum())
                .setText(R.id.tv_per_price,"单价："+item.getCnyPrice()+"CNY")
                .setText(R.id.tv_total_num,"购买总价"+Double.parseDouble(item.getCnyPrice())*Double.parseDouble(item.getBuyTokenNum())+"CNY");


    }
}
